@extends('layouts.app')
@include('package.sidebar')
@section('content')
    @php
        use Illuminate\Support\Facades\Auth;
        use App\Modules\User\Models\Admin;
        $user = Auth::user();
    @endphp
    <div class="content" style="overflow:auto">
        <div class="row custom-invoice" style="min-width: 1000px">
            <div class="row">
                <form method="GET"
                      action="{{ route('admin.package.index') }}">
                    <div class="form-group col-md-2 col-sm-6 col-xs-10" style="width:300px">
                        <input name="shop_id" value="{{$shopId}}" type="hidden">
                        <input name="category" value="{{$category}}" type="hidden">
                        <input class="form-control" type="text" name="name" value="{{ $name }}" placeholder="套系名">
                    </div>
                    <div class="form-group col-md-2 col-sm-10 col-xs-10" style="width:100px">
                        <button class="btn btn-success btn-ms" type="submit">搜索</button>
                    </div>
                </form>
            </div>
            @if($user->is_merchant_staff == Admin::MERCHANT_AUTH)
                @can('merchant_staff_and_package_add')
                    <a class="btn btn-success"
                       href="{{ route("admin.package.create", ['shop_id' => $shopId, 'category' => $category]) }}">添加套系</a>
                @endcan
            @else
                @can('package-add')
                    <a class="btn btn-success"
                       href="{{ route("admin.package.create", ['shop_id' => $shopId, 'category' => $category]) }}">添加套系</a>
                @endcan
            @endif

            <br/>
            <div>
                <table class="table table-striped table-hover">
                    <thead>
                    <tr>
                        <th style="min-width:80px">套系ID</th>
                        <th style="min-width:200px">套系名</th>
                        <th style="min-width:90px">划线价</th>
                        <th style="min-width:90px">价格</th>
                        <th style="min-width:90px">预付金额</th>
                        <th style="min-width:200px">所属店铺</th>
                        <th style="min-width:80px">销量</th>
                        <th style="min-width:80px">状态</th>
                        <th style="min-width:350px">操作</th>
                        <th style="min-width:250px">排序权重</th>
                    </tr>
                    </thead>
                    <tbody>
                    @foreach($data as $item)
                        <tr>
                            <td>{{ $item->id }}</td>
                            <td>{{ $item->name }}</td>
                            <td>{{ $item->display_price/100 }}</td>
                            <td>{{ $item->price/100 }}</td>
                            <td>{{ $item->prepay/100 }}</td>
                            <td>{{ $shop->get($item->shop_id)->name }}</td>
                            <td>{{ $item->sales_volume }}</td>
                            <th>{{ \App\Modules\Package\Models\GoodPackage::$statusShow[$item->status] }}</th>
                            <td>

                                @if($user->is_merchant_staff == Admin::MERCHANT_AUTH)
                                    @can('merchant_staff_and_package_rule')
                                        <a class="btn btn-info btn-xs"
                                           href="{{ route('admin.package.rules.edit', ['id' => $item->id, 'shop_id' => $shopId, 'category' => $category]) }}"><i
                                                class="fa fa-exchange"></i> 返利规则</a>
                                    @endcan
                                    @can('merchant_staff_and_package_edit')
                                        <a class="btn btn-primary btn-xs"
                                           href="{{ route('admin.package.edit', ['id' => $item->id]) }}"><i
                                                class="fa fa-edit"></i> 编辑</a>
                                    @endcan
                                    @can('merchant_staff_and_package_comment')
                                        <a class="btn btn-success btn-xs"
                                           href="{{ route('admin.package.comment', ['id' => $item->id,'category'=>'comment']) }}"><i
                                                class="fa fa-comment-o"></i> 评论</a>
                                    @endcan

                                    @if($item->status == 'off')
                                        @can('merchant_staff_up')
                                            <a class="btn btn-primary btn-xs"
                                               href="{{ route('admin.package.status', ['id' => $item->id]) }}"><i
                                                    class="fa fa-circle-o-notch"></i> 上架</a>
                                        @endcan
                                    @else
                                        @can('merchant_staff_down')
                                            <a class="btn btn-danger btn-xs"
                                               href="{{ route('admin.package.status', ['id' => $item->id]) }}"><i
                                                    class="fa fa-ban"></i> 下架</a>
                                        @endcan
                                    @endif

                                @else
                                    @can('package-rule')
                                        <a class="btn btn-info btn-xs"
                                           href="{{ route('admin.package.rules.edit', ['id' => $item->id, 'shop_id' => $shopId, 'category' => $category]) }}"><i
                                                class="fa fa-exchange"></i> 返利规则</a>
                                    @endcan
                                    @can('package-edit')
                                        <a class="btn btn-primary btn-xs"
                                           href="{{ route('admin.package.edit', ['id' => $item->id]) }}"><i
                                                class="fa fa-edit"></i> 编辑</a>
                                    @endcan
                                    @can('package-comment')
                                        <a class="btn btn-success btn-xs"
                                           href="{{ route('admin.package.comment', ['id' => $item->id,'category'=>'comment']) }}"><i
                                                class="fa fa-comment-o"></i> 评论</a>
                                    @endcan

                                    @if($item->status == 'off')
                                        @can('package_up')
                                            <a class="btn btn-primary btn-xs"
                                               href="{{ route('admin.package.status', ['id' => $item->id]) }}"><i
                                                    class="fa fa-circle-o-notch"></i> 上架</a>
                                        @endcan
                                    @else
                                        @can('package_down')
                                        <a class="btn btn-danger btn-xs"
                                           href="{{ route('admin.package.status', ['id' => $item->id]) }}"><i
                                                class="fa fa-ban"></i> 下架</a>
                                        @endcan
                                    @endif
                                @endif


                                {{--                            @can('package-gift')--}}
                                {{--                                <a class="btn btn-primary btn-xs" href="{{ route('admin.package.gift', ['id' => $item->id, 'shop_id' => $shopId, 'category' => $category]) }}"><i class="fa fa-exchange"></i> 赠品</a>--}}
                                {{--                            @endcan--}}
                            </td>
                            <td>
                                <input type="text" class="col-xs-5 change-sort" data-id="{{ $item->id }}"
                                       value="{{ $item->sort }}"/>
                            </td>
                        </tr>
                    @endforeach
                    </tbody>
                </table>
            </div>
            {{ $data->appends(['name' => $name, 'shop_id' => $shopId, 'category' => $category])->links() }}
        </div>
    </div>
@endsection
@push('scripts')
    <script>
        $('.change-sort').on('change', function () {
            var sort = $(this).val();
            var id = $(this).attr('data-id');
            $.ajax({
                url: '{{ route('admin.package.sort') }}',
                type: "GET",
                dataType: 'json',
                data: {
                    id: id,
                    sort: sort,
                },
                success: function (re) {
                }
            });
        });

    </script>
@endpush
